/*
 * @Author: hongbin
 * @Date: 2023-01-07 11:14:27
 * @LastEditors: hongbin
 * @LastEditTime: 2023-01-07 11:40:58
 * @Description:八叉树碰撞检测
 */
import * as THREE from "three";
import { Octree } from "three/examples/jsm/math/Octree";
import { OctreeHelper } from "three/examples/jsm/helpers/OctreeHelper";
import { Capsule } from "three/examples/jsm/math/Capsule";

export class OctreeCollider {
    worldOctree = new Octree();
    playerCollider = new Capsule(
        new THREE.Vector3(0, 0.35, 0),
        new THREE.Vector3(0, 1, 0),
        0.35
    );
    scene: Object3D;

    constructor(scene: Object3D) {
        this.scene = scene;
        console.time();
        this.worldOctree.fromGraphNode(scene);
        console.timeEnd();
        console.log(this.worldOctree);
    }

    showHelper() {
        const helper = new OctreeHelper(this.worldOctree, new THREE.Color("#00ffaa"));
        this.scene.add(helper);
    }
}
